package com.proton.carepatchtemp.utils;

import android.app.ActivityManager;
import android.content.Context;

import com.apkfuns.logutils.LogUtils;

public class SAppUtils {

    public static String getCurProcessName(Context context) {
        int pid = android.os.Process.myPid();
        ActivityManager activityManager = (ActivityManager) context
                .getSystemService(Context.ACTIVITY_SERVICE);

        for (ActivityManager.RunningAppProcessInfo appProcess : activityManager
                .getRunningAppProcesses()) {
            if (appProcess.pid == pid) {
                LogUtils.e(appProcess.processName);
                return appProcess.processName;
            }
        }
        return null;
    }

    public static boolean isMainProcess(Context context) {
        try {
            if (context.getApplicationInfo().packageName.equals(getCurProcessName(context.getApplicationContext()))) {
                LogUtils.e("current-process-true:" + getCurProcessName(context.getApplicationContext()));
                return true;
            }
        } catch (Throwable e) {
        }
        LogUtils.e("current-process-false:" + getCurProcessName(context.getApplicationContext()));
        return false;
    }
}
